﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Handy_Control_Learn.Utils
{
    public class RegExpUtil
    {
        #region 房屋名称测试代码
        //{
        //string str = "崇礼区乌拉哈达村富贵家园小区4单元";
        //string str2 = "崇礼县高家营镇乌拉哈达村贵府金街小区01号商业楼";
        //string str3 = "崇礼区长青路1号院住宅楼";
        //string str4 = "崇礼区北新街嘉泰苑小区5号商住楼";
        //string str5 = "张家口市崇礼区商贸新区崇礼伊人风情街02号综合楼B段";

        //Stopwatch stopwatch = new Stopwatch();
        //stopwatch.Start();
        //string res = Match(str5);
        //stopwatch.Stop();
        //Console.WriteLine(res);
        //Console.WriteLine($"执行时间： {stopwatch.ElapsedMilliseconds}");
        //}
        #endregion


        #region 房屋单元号处理
        //{
        //string str1 = "1单元2302";
        //string str2 = "甲单元502";
        //string str3 = "11号商住楼1单元201";
        //string str4 = "A段1单元201";

        //string res = MatchUnitNumber(str3);
        //Console.WriteLine(res);
        //}
        #endregion


        public static string MatchUnitNumber(string input)
        {
            string pattern = @"(?:.*?)(?<UnitNum>[A-Z0-9\u4e00-\u9fa5]*)(?:单元.*?)";
            Match match = Regex.Match(input, pattern);
            if (match.Success)
            {
                GroupCollection groups = match.Groups;
                Group group = groups["UnitNum"];
                return group.Value;
            }
            return null;
        }

        public static string MatchBuildName(string input)
        {
            // string pattern = @"(.*?)(?<buildNum>[A-Z0-9\u4e00-\u9fff](单元|号楼|号住宅楼|商住楼|号商业楼))";
            // string pattern = @"(.*?)(?<buildNum>[A-Z0-9]*(栋|座|座楼|号(底商|阁楼|楼|院住宅楼|住宅楼|商业楼|商住楼|综合楼)|单元))";
            string pattern = @"";
            Match match = Regex.Match(input, pattern);
            if (match.Success)
            {
                GroupCollection groups = match.Groups;
                Group group = groups["buildNum"];
                return group.Value;
            }
            return null;
        }

    }
}
